import '@tarojs/async-await'
import Taro, { Component } from '@tarojs/taro'
import { Provider } from '@tarojs/redux'

import Index from './pages/index'

import configStore from './store'

// Used by weapp only
import CustomTabBar from '../custom-tab-bar'

import './app.scss'

import { courseListActions } from './actions/courseList'

// 如果需要在 h5 环境中开启 React Devtools
// 取消以下注释：
// if (process.env.NODE_ENV !== 'production' && process.env.TARO_ENV === 'h5')  {
//   require('nerv-devtools')
// }

const store = configStore()

class App extends Component {

  config = {
    pages: [
      'pages/index/index',
      'pages/creator/index',
      'pages/detail/index',
      'pages/signScan/index',
      'pages/center/index',
    ],
    permission: {
      "scope.userLocation": {
        desc: "我们需要获得您的许可来选取位置"
      }
    },
    window: {
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#fff',
      navigationBarTitleText: 'WeChat',
      navigationBarTextStyle: 'black'
    },
    tabBar: {
      custom: true,
      selectedColor: '#6190E8',
      list: [
        {
          "pagePath": "pages/index/index",
          "text": "首页",
          "iconPath": "assets/imgs/home.png",
          "selectedIconPath": "assets/imgs/home_select.png",
        },
        {
          "pagePath": "pages/signScan/index",
          "text": "签到",
          "iconPath": "assets/imgs/qr_code.png",
          "selectedIconPath": "assets/imgs/qr_code.png",
        },
        {
          "pagePath": 'pages/center/index',
          "text": "我的",
          "iconPath": "assets/imgs/more.png",
          "selectedIconPath": "assets/imgs/more_select.png",
        }
      ]
    }
  }

  componentDidMount() {
    store.dispatch(courseListActions.fetchAllCourses())
  }

  componentDidShow() { }

  componentDidHide() { }

  componentDidCatchError() { }

  // 在 App 类中的 render() 函数没有实际作用
  // 请勿修改此函数
  render() {
    return (
      <Provider store={store}>
        <Index />
      </Provider>
    )
  }
}

Taro.render(<App />, document.getElementById('app'))
